package com.yan;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @author yanheng
 * @date 2020/6/9
 */
public class IdGenerator3 {
    private AtomicLong id = new AtomicLong();

    private IdGenerator3() {}

    private static class SingletonHolder {
        private static final IdGenerator3 instance = new IdGenerator3();
    }

    public static IdGenerator3 getInstance() {
        return SingletonHolder.instance;
    }

    public long getId() {
        return id.incrementAndGet();
    }

    public static void main(String[] args) {
        System.out.println(IdGenerator3.getInstance().getId());
        System.out.println(IdGenerator3.getInstance().getId());
        System.out.println(IdGenerator3.getInstance().getId());
    }
}
